clear all

set seed 249233
local bsiter = 10
 


cd "/Users/sambuehl/Dropbox/Demand_for_Information/DATA_ANALYSIS/"

* make datasets lean



set more off

use "data/data_all.dta", replace

drop if session == 1 

merge m:1 subj using "data/alphas.dta"
drop _merge

gen logit_p11 = log(p11/(1-p11))
gen logit_p00 = log(p00/(1-p00))
gen loglik11 = log(a/(1-b))
gen loglik00 = log(b/(1-a))

drop if info_str == 11

save "data/pool.dta", replace

***** initial estimate


use "data/pool.dta", replace

capture: drop tag_subj
egen tag_subj = tag(subj)

keep if tag_subj == 1
keep sub id alpha se_alpha

gen id_new = _n

expandby 10, by(id_new)
sort id_new
gen info_structure = _n
replace info_structure = info_structure - 10*floor(info_structure/10)
replace info_structure = 10 if info_structure == 0

merge m:1 subject info_struc using "data/pool.dta"
drop if _merge == 2
drop _merge


gen pred_logit_p11 = alpha * loglik11
gen pred_logit_p00 = alpha * loglik00


* estimation 

gen pred_p11 = exp(pred_logit_p11)/(1 + exp(pred_logit_p11))
gen pred_p00 = exp(pred_logit_p00)/(1 + exp(pred_logit_p00))
replace pred_p00 = 1 if pred_p00 == .
gen pred_v_pred = b_p1 * pred_p11 + (1 - b_p1) * pred_p00




******* averaged over information structures

gen diff = v - v_pred_true_all
gen diff_sim = pred_v_pred - v_pred_true_all
gen diff_emp = v_pred - v_pred_true_all
gen diff_emp_upd = v_pred_true_uncond - v_pred_true_all


sort subject
by subject: egen mean_diff = mean(diff)
by subject: egen mean_diff_sim = mean(diff_sim)
by subject: egen mean_diff_emp = mean(diff_emp)
by subject: egen mean_diff_emp_upd = mean(diff_emp_upd)


gen dev_bayes_p11_p00 = dev_bayes_p11 + dev_bayes_p00
// xi: pcorr diff dev_bayes_p11_p00 v_pred_true_all i.session i.group if rogue == 0
xi: pcorr diff dev_bayes_p11_p00 i.session i.group

xi: pcorr mean_diff mean_diff_emp i.session i.group if rogue == 0

reg mean_diff mean_diff_sim mean_diff_emp 
reg mean_diff mean_diff_sim 
reg mean_diff mean_diff_emp 


reg diff diff_emp 
outreg2 diff_emp using "tables/across_v_reg_all.tex", addtext(10 percent trim, no) tex replace
reg diff diff_sim 
outreg2 diff_sim using "tables/across_v_reg_all.tex", addtext(10 percent trim, no) tex
reg diff diff_emp diff_sim 
outreg2 diff_emp diff_sim using "tables/across_v_reg_all.tex", addtext(10 percent trim, no) tex(frag)


gen extreme = 0
su alpha,d
replace extreme = 1 if alpha < r(p10)+0.001
replace extreme = 1 if alpha >  r(p90)-0.001


reg diff diff_emp if extreme == 0
outreg2 diff_emp using "tables/across_v_reg_all.tex", addtext(10 percent trim, yes) tex
reg diff diff_sim if extreme == 0
outreg2 diff_sim using "tables/across_v_reg_all.tex", addtext(10 percent trim, yes) tex
reg diff diff_emp diff_sim if  extreme == 0
outreg2 diff_emp diff_sim using "tables/across_v_reg_all.tex", addtext(10 percent trim, yes) tex(frag)


// Referee comment: Can it all be explained by risk preferences? 
// Approach: Those things are information structure specific, so it depends 
// on the extent to which information structure fixed-effects increase R^2. 
// Note, however, that this does not capture individual-level variations in risk preferences. 

reg diff diff_emp diff_sim, cl(subj)
areg diff diff_emp diff_sim, a(info_str)
outreg2 diff_emp diff_sim using "tables/across_v_reg_infoFE.tex", dec(3) replace tex(frag)

reg diff diff_sim, cl(subj)
areg diff diff_sim, a(info_str)
outreg2 diff_emp diff_sim using "tables/across_v_reg_infoFE.tex", dec(3) tex(frag)

reg diff diff_emp, cl(subj)
areg diff diff_emp, a(info_str)
outreg2 diff_emp diff_sim using "tables/across_v_reg_infoFE.tex", dec(3) tex(frag)

areg diff , a(info_str)

gen infoStrSubj = info_str * subj

areg diff , a(infoStrSubj)

areg diff , a(subj)
